# -*- coding: utf-8 -*-
#
#   Copyright (C) 2007, 2008 Yves Junqueira (yves@cetico.org) 
#
#    This file is part of GeekDNS.
#
#    GeekDNS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    GeekDNS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with GeekDNS.  If not, see <http://www.gnu.org/licenses/>.

import sys
import md5
import os.path
import random
import string
import re
from twill.commands import *

import turbogears

file="dev.cfg"
if os.path.exists("prod.cfg"): file="prod.cfg"
turbogears.update_config(configfile=file,
modulename="geekroot.config")
from geekroot import model


class Commands:

  def __init__(self):
    pass

  def run_ls(self):
    for server in (model.Server.select(model.AND(model.Server.q.main_ip!='',
      model.Server.q.active==True))):

      print "%s [%s] %s %s" % (server.main_ip, server.domain,
          server.price_real, server.owner.email_address)
    sys.exit(0)


def usage():
  print """
  %s <command> [options]

  commands:

  addcactihost <host>

  ls
  """ % sys.argv[0]


def main():

  try:
    command=sys.argv[1]
  except:
    print "missing parameter"
    usage() 
    sys.exit(1)
  
  c=Commands()
  command='run_' + sys.argv[1]
  if not hasattr(c,command):
    print "unknown command"
    usage()
    sys.exit(1)
  run=getattr(c,command)
  run(*sys.argv[2:])
  sys.exit(0)


if __name__ == '__main__':
  main()
